<?php
//dicts Model
class PackagesModel
{
	private $id;
	private $packagename;
	private $packagedescription;
	/*SET*/
	public function setId($id)
	{
		$this->id=$id;
		}
	public function setPackagename($packagename)
	{
		$this->packagename=$packagename;
		}
	public function setPackagedescription($packagedescription)
	{
		$this->packagedescription=$packagedescription;
		}
		/*GET*/
	public function getId()
	{
		return $this->id;
		}
	public function getPackagename()
	{
		return $this->packagename;
		}
	public function getPackagedescription()
	{
		return $this->packagedescription;
		}
	
}
class PackageQuery
{
	protected $package;
	public function PackageQuery()
	{
		$this->package=new PackagesModel();
		}
		public function inserQuery()
		{
			$q="INSERT INTO `laodicts`.`packages` (`packagename`, `packagedescription`) VALUES (%s, %s);";
			$q=sprintf($q,
			mysql_escape_string($this->package->getPackagename()),
			mysql_escape_string($this->package->getPackagedescription()));
			
			return mysql_query($q);
			}
		public function updateQuery()
		{
			$q="UPDATE `laodicts`.`packages` SET `packagename` = %s,
			`packagedescription` = %s,
			WHERE `packages`.`id` =%d ";
			$q=sprintf($q,
			mysql_escape_string($this->package->getPackagename()),
			mysql_escape_string($this->package->getPackagedescription()),
			mysql_escape_string($this->package->getId()));
			return mysql_query($q);
			}
		public function deleteQuery()
		{
			$q="delete packages where id=%d";
			$q=sprintf($q,mysql_escape_string($this->package->getId()));
			return mysql_query($q);
			}
		public function selectQuery($packageid=-1)
		{
			$arr=array();
			$i=0;
			$query="SELECT * FROM packages";
			if($packageid>1)
			{
				
				$query=sprintf("SELECT * FROM packages where id =$d",mysql_escape_string($packageid));
			}
			$result=mysql_query($query);
			
			$num=mysql_numrows($result);
			
			while ($i < $num) {
			$this->package=new PackagesModel();
			$this->package->setId(mysql_result($result,$i,"id"));					
			$this->package->setPackagename(mysql_result($result,$i,"packagename"));
			$this->package->setPackagedescription(mysql_result($result,$i,"packagedescription"));
					
			$arr[]=$this->package;
			
			
			++$i;
			}

				
			return $arr;
		}
}
?>
